package chapter9;

public class CommissionEmployee extends Object {

	private String firstName;
	private String lastName;
	private String socialSecurityNumber;
	private double grossSales;
	private double commissionRate;

	public CommissionEmployee(String first, String last, String ssn,
			double sales, double rate) {
		firstName = first;
		lastName = last;
		socialSecurityNumber = ssn;
		setGrossSales(sales);
		setCommissionRate(rate);
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getSocialSecurityNumber() {
		return socialSecurityNumber;
	}

	public void setSocialSecurityNumber(String socialSecurityNumber) {
		this.socialSecurityNumber = socialSecurityNumber;
	}

	public double getGrossSales() {
		return grossSales;
	}

	public void setGrossSales(double sales) {
		grossSales = (sales < 0.0) ? 0.0 : sales;
	}

	public double getCommissionRate() {
		return commissionRate;
	}

	public void setCommissionRate(double rate) {
		commissionRate = (rate > 0.0 && rate < 1.0) ? rate : 0.0;
	}

	public double earnigns() {
		return commissionRate * grossSales;
	}

	@Override
	public String toString() {
		return String.format("%s: %s %s\n%s: %s\n%s: %.2f\n%s: %.2f",
			"Comission employee", firstName, lastName,
			"Social security number", socialSecurityNumber,
			"Gross sales", grossSales,
			"Commission rate", commissionRate);
	}

}
